function ReplayContent(id,body, date, image, type, name) {
	this.id = id;
	this.body = body;
	this.date = date;
	this.image = image;
	this.type = type;
	this.name = name;
}

function ReReplayContent(name, text, time,image){
	this.name = name;
	this.text = text;
	this.time = time;
	this.image =image;
}

function getText(elem) {
	var text = "";
	if (elem) {
		if (elem.childNodes) {
			for (var i = 0; i < elem.childNodes.length; i++) {
				var child = elem.childNodes[i];
				if (child.nodeValue){
					text += child.nodeValue;
				}
				else {
					if (child.childNodes[0]){
						if (child.childNodes[0].nodeValue){
							text += child.childNodes[0].nodeValue;
						}
					}
				}
			}
		}
	}
	return text;
}

var ajaxReq = new AjaxRequest();
var isFinished;
function loadContent(){
	document.getElementById("content").innerHTML = "<img src='wait.gif'  id='waitImage' alt='Loading...' />";
	//ajaxReq.send("POST", "TaskContent", handleRequest);
	sendXMLPost("TaskContent",null, handleRequest);
}

function handleRequest(responseXML) {
	//if (ajaxReq.getReadyState() == 4 && ajaxReq.getStatus() == 200) {
		var xmlData = responseXML.getElementsByTagName("content")[0];
		
		var postNode = xmlData.getElementsByTagName("post")[0];
		isFinished = getText(postNode.getElementsByTagName("status")[0]) == "no" ? false : true;
		document.getElementById("personPhoto").src = getText(postNode.getElementsByTagName("image")[0]);
		document.getElementById("post_id").innerHTML = getText(postNode.getElementsByTagName("id")[0]);
		document.getElementById("personName_upText").innerHTML = getText(postNode.getElementsByTagName("author")[0]);
		document.getElementById("detailContent_upText").innerHTML = getText(postNode.getElementsByTagName("body")[0]);
		document.getElementById("deadLine_upText").innerHTML = getText(postNode.getElementsByTagName("date")[0]);
		document.getElementById("reward_upText").innerHTML = getText(postNode.getElementsByTagName("reward")[0]);
		
		var entries = xmlData.getElementsByTagName("entry");
		//alert("entries.length "+entries.length);
		for (var i = 0; i < entries.length; i++) {
			replayContent.push(	new ReplayContent(
									getText(entries[i].getElementsByTagName("id")[0]),
									getText(entries[i].getElementsByTagName("body")[0]),
									getText(entries[i].getElementsByTagName("date")[0]),
              						getText(entries[i].getElementsByTagName("image")[0]),
									getText(entries[i].getElementsByTagName("type")[0]),
									getText(entries[i].getElementsByTagName("author")[0])
									)
						);
			if(replayContent[i].type == "pass"){
				allPassReplayContentCounts++;
			}else if(replayContent[i].type == "failed"){
				allFailedReplayContentCounts++;
			}else if(replayContent[i].type == "waiting"){
				allWaitingReplayContentCounts++;
			}
			allReplayContentCounts++;
		}
		
	//}
	//alert(allPassReplayContentCounts);
	//alert(allFailedReplayContentCounts);
	//alert(allWaitingReplayContentCounts);
	//alert(allReplayContentCounts);
	//alert("replayContent.length "+replayContent.length);
	
	if(allPassReplayContentCounts == 0){
		allPassReplayPageCounts = 0;
	}else{
		if(parseInt(allPassReplayContentCounts%4) == 0){
			allPassReplayPageCounts =  parseInt(allPassReplayContentCounts/4);
		}else{
			allPassReplayPageCounts =  parseInt(allPassReplayContentCounts/4) + 1;
		}
	}
	
	if(allFailedReplayContentCounts == 0){
		allFailedReplayPageCounts = 0;
	}else{
		if(parseInt(allFailedReplayContentCounts%4) == 0){
			allFailedReplayPageCounts =  parseInt(allFailedReplayContentCounts/4);
		}else{
			allFailedReplayPageCounts =  parseInt(allFailedReplayContentCounts/4) + 1;
		}
	}
	
	if(allWaitingReplayContentCounts == 0){
		allWaitingReplayPageCounts = 0;
	}else{
		if(parseInt(allWaitingReplayContentCounts%4) == 0){
			allWaitingReplayPageCounts =  parseInt(allWaitingReplayContentCounts/4);
		}else{
			allWaitingReplayPageCounts =  parseInt(allWaitingReplayContentCounts/4) + 1;
		}
	}
	
	if(allReplayContentCounts == 0){
		allReplayPageCounts = 0;
	}else{
		if(parseInt(allReplayContentCounts%4) == 0){
			allReplayPageCounts =  parseInt(allReplayContentCounts/4);
		}else{
			allReplayPageCounts =  parseInt(allReplayContentCounts/4) + 1;
		}
	}
	//alert(allPassReplayPageCounts);
	//alert(allFailedReplayPageCounts);
	//alert(allWaitingReplayPageCounts);
	//alert(allReplayPageCounts);
	isFirst = true;
	showReplayContent("all", 1);
	
	setUserName();
	
}


function setUserName() {
	document.getElementById("welcomeText").innerHTML = "欢迎回来，" + getUserName();
}

var reReplayContent = new Array();
var showContent = new Array();
var allPassReplayContentCounts = 0;
var allFailedReplayContentCounts = 0;
var allWaitingReplayContentCounts = 0;
var allReplayContentCounts = 0;

var allPassReplayPageCounts = 0;
var allFailedReplayPageCounts = 0;
var allWaitingReplayPageCounts = 0;
var allReplayPageCounts = 0;
var currentPage = 1;

var srcParent;

function upReplayButton(event){
	//alert(window.event.srcElement.parentNode.parentNode.parentNode.innerHTML);		
	//ajaxReq.send("GET", "xxx1.xml", handleRequest);
	//alert(window.event.srcElement.parentNode.parentNode.parentNode.childNodes[3].innerHTML);
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	srcParent = window.event.srcElement.parentElement;
	reReplayContent.length = 0;
	var  node = window.event.srcElement.parentNode.parentNode.parentNode.childNodes[1];
	
	while(node.firstChild){
		node.removeChild(node.firstChild);
	}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////	
	var arguments = "<content>";
	arguments = addTag(arguments, "offerId", event.srcElement.parentElement.parentElement.parentElement.id);
	//arguments = addTag(arguments, "body", event.srcElement.parentElement.parentElement.children[0].children[0].value);
	arguments += "</content>";
	sendXMLPost("GetQA",arguments, handleRequest_reReplayContent);
	
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function handleRequest_reReplayContent(responseXML){
	var xmlData = responseXML.getElementsByTagName("content")[0];
		
	//var postNode = xmlData.getElementsByTagName("post")[0];
	//isFinished = getText(postNode.getElementsByTagName("status")[0]) == "no" ? false : true;
	//document.getElementById("post_id").innerHTML = getText(postNode.getElementsByTagName("id")[0]);
	//document.getElementById("personName_upText").innerHTML = getText(postNode.getElementsByTagName("author")[0]);
	//document.getElementById("detailContent_upText").innerHTML = getText(postNode.getElementsByTagName("body")[0]);
	//document.getElementById("deadLine_upText").innerHTML = getText(postNode.getElementsByTagName("date")[0]);
	//document.getElementById("reward_upText").innerHTML = getText(postNode.getElementsByTagName("reward")[0]);
		
	var entries = xmlData.getElementsByTagName("entry");
		//alert("entries.length "+entries.length);
	for (var i = 0; i < entries.length; i++) {
		reReplayContent.push(new ReReplayContent(
								getText(entries[i].getElementsByTagName("name")[0]),
								getText(entries[i].getElementsByTagName("text")[0]),
								getText(entries[i].getElementsByTagName("time")[0]),
								getText(entries[i].getElementsByTagName("image")[0])
								)
					);
	}
	
	showReReplayContent();
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function showReplayContent(type ,pageNumber){
	showContent.length = 0;
	currentPage = pageNumber;
	
	var node = document.getElementById("content");
	while(node.firstChild){
		node.removeChild(node.firstChild);
	}
	
	//alert(currentPage);
	if(type == "all"){
		var i = 0;
		while (i < replayContent.length) {
			showContent.push(replayContent[i]);
			i++;		
		}
		var k = 0, contentListHTML = "";
		while(k < showContent.length){
			if(k >= (pageNumber-1)*4 && k < pageNumber*4){
				contentListHTML += showContent[k].toHTML();
			}
			k++;
		}
		var node = document.getElementById("lastPage2");
		while(node.firstChild){
			node.removeChild(node.firstChild);
		}
		document.getElementById("lastPage2").innerHTML = allReplayPageCounts;
	}else if(type == "refuse"){
		var i = 0;
		while (i < replayContent.length) {
			if(replayContent[i].type == "failed"){
				showContent.push(replayContent[i]);
			}		
			i++;
		}
		//alert(showContent.length);
		var k = 0, contentListHTML = "";
		while(k < showContent.length){
			if(k >= (pageNumber-1)*4 && k < pageNumber*4){
				contentListHTML += showContent[k].toHTML();
			}
			k++;
		}
		var node = document.getElementById("lastPage2");
		while(node.firstChild){
			node.removeChild(node.firstChild);
		}
		document.getElementById("lastPage2").innerHTML = allFailedReplayPageCounts;
	}else if(type == "wait"){
		var i = 0;
		while (i < replayContent.length) {
			if(replayContent[i].type == "waiting"){
				showContent.push(replayContent[i]);
			}		
			i++;
		}
		//alert(showContent.length);
		var k = 0, contentListHTML = "";
		while(k < showContent.length){
			if(k >= (pageNumber-1)*4 && k < pageNumber*4){
				contentListHTML += showContent[k].toHTML();
			}
			k++;
		}
		var node = document.getElementById("lastPage2");
		while(node.firstChild){
			node.removeChild(node.firstChild);
		}
		document.getElementById("lastPage2").innerHTML = allWaitingReplayPageCounts;
	}else if(type == "pass"){
		var i = 0;
		while (i < replayContent.length) {
			if(replayContent[i].type == "pass"){
				showContent.push(replayContent[i]);
			}		
			i++;
		}
		//alert(showContent.length);
		var k = 0, contentListHTML = "";
		while(k < showContent.length){
			if(k >= (pageNumber-1)*4 && k < pageNumber*4){
				contentListHTML += showContent[k].toHTML();
			}
			k++;
		}
		var node = document.getElementById("lastPage2");
		while(node.firstChild){
			node.removeChild(node.firstChild);
		}
		document.getElementById("lastPage2").innerHTML = allPassReplayPageCounts;
	}
	//alert(contentListHTML);
	if(isFirst){		
		addPages(showContent.length, lengthToPage(showContent.length));
		//var number =  parseInt(pageNumber%6);
		setPage(pageNumber);
	}
	
	document.getElementById("content").innerHTML = decodeURIComponent(contentListHTML);
}

var isFirst = true;

ReplayContent.prototype.toHTML = function() {
	 var contentHTML = "";
	 var pass;
	 var nopass;
	 if (this.type == "pass") {
		 pass = "pass_checked";
		 nopass = "nopass_unchecked";
	 }else if (this.type == "waiting") {
		 pass = "pass_unchecked";
		 nopass = "nopass_unchecked";
	 }else if (this.type == "failed") {
		 pass = "pass_unchecked";
		 nopass = "nopass_checked";
	 }
	 
	 if (this.image) {
		 	contentHTML += "<div class='replytextTag' id='" + this.id +
		 			"'>"
				+ "<div class='replytextTag_Main'>"
				+ "<div class='" + nopass +
						"' onclick='nopass_clicked(event);'></div>"
				+ "<div class='" +pass+
						"' onclick='pass_clicked(event);'></div>"
				+ "<div class='replypersonPhoto'><img src='"
				+ this.image
				+ "'/></div>"
				+ "<div class='personName_middleLabel' id='personName_middleLabel'>用户名：</div>"
				+ "<div class='personName_middText' id='personName_middText'>"
				+ this.name
				+ "</div>"
				+ "<div class='replyContent_middleLabel' id='replyContent_middleLabel'>我要接任务，我想对你说：</div>"
				+ "<div class='replyContent'><span id='replyContent'>"
				+ this.body
				+ "</span></div>"
				+ "<div class='replyButton'><span id='replyButton' onclick='upReplayButton(event);'></span></div>"
				+ "</div>" + "<div id='add'></div>" + "</div> ";
	 }
	 else {
		 contentHTML += "<div class='replytextTag' id='" + this.id +
		 		"'>"
				+ "<div class='replytextTag_Main'>"
				+ "<div class='" + nopass +
						"' onclick='nopass_clicked(event);'></div>"
				+ "<div class='" + pass +
						"' onclick='pass_clicked(event);'></div>"
				+ "<div class='replypersonPhoto'><img src='#'/></div>"
				+ "<div class='personName_middleLabel' id='personName_middleLabel'>用户名：</div>"
				+ "<div class='personName_middText' id='personName_middText'>"
				+ this.name
				+ "</div>"
				+ "<div class='replyContent_middleLabel' id='replyContent_middleLabel'>我要接任务，我想对你说：</div>"
				+ "<div class='replyContent'><span id='replyContent'>"
				+ this.body
				+ "</span></div>"
				+ "<div class='replyButton'><span id='replyButton' onclick='upReplayButton(event);'></span></div>"
				+ "</div>" + "<div id='add'></div>" + "</div> ";
	}
	
	return contentHTML;
};

function showReReplayContent(){
	//alert(reReplayContent.length)
	srcParent.parentElement.parentElement.children[1].innerHTML += "<div class='replyAddContent'></div>";
	var i = 0;
	for(i = 0; i < reReplayContent.length; i++){
		srcParent.parentElement.parentElement.children[1].firstChild.innerHTML += "<div class='replyAddContent_Node'><div class='replyAddContent_Node_image'><img src=" + reReplayContent[i].image + "></div><div class='replyAddContent_Node_name'>" + reReplayContent[i].name + "</div><div class='replyAddContent_Node_label'>" + "回复： " + "</div><div class='replyAddContent_Node_text'>" +  reReplayContent[i].text + "</div><div class='replyAddContent_Node_time'>" + reReplayContent[i].time + "</div></div>";
	}
	
	
	
	srcParent.parentElement.parentElement.children[1].innerHTML += "<div class='replyAddTag'><div class='replyAddtext'><input id='replyAddtext' size='65'/></div><div class='replyAdd_Cancel'><span id='replyAdd_Cancel' onclick='replayCancel();'></span></div><div class='replyAdd_Ok'><span id='replyAdd_Ok' onclick='replayOK(event);'></span></div></div>";
	
	//alert(window.event.srcElement.parentNode.parentNode.parentNode.childNodes[3].innerHTML);
}

function replayCancel(){
	var node=window.event.srcElement.parentNode.parentNode.parentNode;
	while(node.firstChild){
		node.removeChild(node.firstChild);
	}
}

function replayOK(event){
	//var node = window.event.srcElement.parentNode.parentNode.parentNode;
	//alert(window.event.srcElement.parentNode.parentNode.childNodes[0].childNodes[0].value);
	if (isFinished) {
		alert("任务已完成!不能继续回复！");
		return;
	}
	var text = window.event.srcElement.parentNode.parentNode.childNodes[0].childNodes[0].value;
	if(text){
		var arguments = "<content>";
		arguments = addTag(arguments, "username", getUserName());
		arguments = addTag(arguments, "offerId", event.srcElement.parentElement.parentElement.parentElement.parentElement.id);
		arguments = addTag(arguments, "body", event.srcElement.parentElement.parentElement.children[0].children[0].value);
		arguments += "</content>";
		var url = "CreateQA";
		sendXMLPost(url, arguments, null);
		
		reReplayContent.push(new ReReplayContent(getUserName(),text));
		addReReplayContent();
		window.event.srcElement.parentNode.parentNode.childNodes[0].childNodes[0].value= "";
	}else{
		alert("请检查输入内容!");
	}
}

function addReReplayContent(){
	
	window.event.srcElement.parentNode.parentNode.parentNode.firstChild.innerHTML += "<div class='replyAddContent_Node'><div class='replyAddContent_Node_image'><img src=" + reReplayContent[reReplayContent.length-1].photo + "></div><div class='replyAddContent_Node_name'>" + reReplayContent[reReplayContent.length-1].name + "</div><div class='replyAddContent_Node_label'>" + "回复： " + "</div><div class='replyAddContent_Node_text'>" +  reReplayContent[reReplayContent.length-1].text + "</div><div class='replyAddContent_Node_time'>" + reReplayContent[reReplayContent.length-1].time + "</div></div>";
}
	
	

var replayContent = new Array();


function setPass(id) {
	sendXMLPost("SetMode","<TaskMode><mode>pass</mode><id>"+id+"</id></TaskMode>", null);
}

function setNoPass(id) {
	sendXMLPost("SetMode","<TaskMode><mode>nopass</mode><id>"+id+"</id></TaskMode>", null);
}

function setWaiting(id) {
	sendXMLPost("SetMode","<TaskMode><mode>waiting</mode><id>"+id+"</id></TaskMode>", null);
}
function nopass_clicked(event){
	if (isFinished == true
			|| document.getElementById("personName_upText").innerHTML != getUserName())
		return;
	var id = event.srcElement.parentElement.parentElement.id;
	if(window.event.srcElement.className == "nopass_unchecked"){
		setNoPass(id);
		window.event.srcElement.className = "nopass_checked";
		if(window.event.srcElement.parentNode.childNodes[1].className == "pass_checked"){
			window.event.srcElement.parentNode.childNodes[1].className = "pass_unchecked";
		}
	}else{
		setWaiting(id);
		window.event.srcElement.className = "nopass_unchecked";
		
	}
}

function pass_clicked(event){
	if (isFinished == true
			|| document.getElementById("personName_upText").innerHTML != getUserName())
		return;
	var id = event.srcElement.parentElement.parentElement.id;
	if(window.event.srcElement.className == "pass_unchecked"){
		setPass(id);
		window.event.srcElement.className = "pass_checked";
		if(window.event.srcElement.parentNode.childNodes[0].className == "nopass_checked"){
			window.event.srcElement.parentNode.childNodes[0].className = "nopass_unchecked";
		}
	}else{
		setWaiting(id);
		window.event.srcElement.className = "pass_unchecked";
	}
}

function openPersonPage(){
	window.open("personPage.html","_blank");
}

function focusTag(type){
	if(type == "all"){
		document.getElementById("passTag").className = "passTagNormal";
		document.getElementById("waitTag").className = "waitTagNormal";
		document.getElementById("refuseTag").className = "refuseTagNormal";
		document.getElementById("allTag").className = "allTagChecked";
	}else if(type == "refuse"){
		document.getElementById("passTag").className = "passTagNormal";
		document.getElementById("waitTag").className = "waitTagNormal";
		document.getElementById("refuseTag").className = "refuseTagChecked";
		document.getElementById("allTag").className = "allTagNormal";
	}else if(type == "wait"){
		document.getElementById("passTag").className = "passTagNormal";
		document.getElementById("waitTag").className = "waitTagChecked";
		document.getElementById("refuseTag").className = "refuseTagNormal";
		document.getElementById("allTag").className = "allTagNormal";
	}else if(type == "pass"){
		document.getElementById("passTag").className = "passTagChecked";
		document.getElementById("waitTag").className = "waitTagNormal";
		document.getElementById("refuseTag").className = "refuseTagNormal";
		document.getElementById("allTag").className = "allTagNormal";
	}
}

var typeFlag = "all";

function allTagClicked(){
	isFirst = true;
	showReplayContent("all", 1);	
	focusTag("all");
	typeFlag = "all";
}

function refuseTagClicked(){
	isFirst = true;
	showReplayContent("refuse", 1);
	focusTag("refuse");
	typeFlag = "refuse";
}

function waitTagClicked(){
	isFirst = true;
	showReplayContent("wait", 1);
	focusTag("wait");
	typeFlag = "wait";
}

function passTagClicked(){
	isFirst = true;
	showReplayContent("pass", 1);
	focusTag("pass");
	typeFlag = "pass";
}

function changePage(flag){
	var pageID = setPage(flag);
	var pageNumber = parseInt(document.getElementById(pageID).firstChild.nodeValue);
	currentPage = pageNumber;
	isFirst = false;
	showReplayContent(typeFlag, pageNumber);
}

function setPage(flag){
	var pageID;
	if(flag == 1 || flag == "1"){
		pageID = "pageNumber1";
		if(document.getElementById("page1")){
			document.getElementById("page1").className = "page1_checked";
		}
		if(document.getElementById("page2")){
			document.getElementById("page2").className = "page2_normal";
		}
		if(document.getElementById("page3")){
			document.getElementById("page3").className = "page3_normal";
		}
		if(document.getElementById("page4")){
			document.getElementById("page4").className = "page4_normal";
		}
		if(document.getElementById("page5")){
			document.getElementById("page5").className = "page5_normal";
		}
		if(document.getElementById("page6")){
			document.getElementById("page6").className = "page6_normal";
		}
	}else if(flag == 2 || flag == "2"){
		pageID = "pageNumber2";
		if(document.getElementById("page1")){
			document.getElementById("page1").className = "page1_normal";
		}
		if(document.getElementById("page2")){
			document.getElementById("page2").className = "page2_checked";
		}
		if(document.getElementById("page3")){
			document.getElementById("page3").className = "page3_normal";
		}
		if(document.getElementById("page4")){
			document.getElementById("page4").className = "page4_normal";
		}
		if(document.getElementById("page5")){
			document.getElementById("page5").className = "page5_normal";
		}
		if(document.getElementById("page6")){
			document.getElementById("page6").className = "page6_normal";
		}
	}else if(flag == 3 || flag == "3"){
		pageID = "pageNumber3";
		if(document.getElementById("page1")){
			document.getElementById("page1").className = "page1_normal";
		}
		if(document.getElementById("page2")){
			document.getElementById("page2").className = "page2_normal";
		}
		if(document.getElementById("page3")){
			document.getElementById("page3").className = "page3_checked";
		}
		if(document.getElementById("page4")){
			document.getElementById("page4").className = "page4_normal";
		}
		if(document.getElementById("page5")){
			document.getElementById("page5").className = "page5_normal";
		}
		if(document.getElementById("page6")){
			document.getElementById("page6").className = "page6_normal";
		}
	}else if(flag == 4 || flag == "4"){
		pageID = "pageNumber4";
		if(document.getElementById("page1")){
			document.getElementById("page1").className = "page1_normal";
		}
		if(document.getElementById("page2")){
			document.getElementById("page2").className = "page2_normal";
		}
		if(document.getElementById("page3")){
			document.getElementById("page3").className = "page3_normal";
		}
		if(document.getElementById("page4")){
			document.getElementById("page4").className = "page4_checked";
		}
		if(document.getElementById("page5")){
			document.getElementById("page5").className = "page5_normal";
		}
		if(document.getElementById("page6")){
			document.getElementById("page6").className = "page6_normal";
		}
	}else if(flag == 5 || flag == "5"){
		pageID = "pageNumber5";
		if(document.getElementById("page1")){
			document.getElementById("page1").className = "page1_normal";
		}
		if(document.getElementById("page2")){
			document.getElementById("page2").className = "page2_normal";
		}
		if(document.getElementById("page3")){
			document.getElementById("page3").className = "page3_normal";
		}
		if(document.getElementById("page4")){
			document.getElementById("page4").className = "page4_normal";
		}
		if(document.getElementById("page5")){
			document.getElementById("page5").className = "page5_checked";
		}
		if(document.getElementById("page6")){
			document.getElementById("page6").className = "page6_normal";
		}
	}else if(flag == 6 || flag == "6"){
		pageID = "pageNumber6";
		if(document.getElementById("page1")){
			document.getElementById("page1").className = "page1_normal";
		}
		if(document.getElementById("page2")){
			document.getElementById("page2").className = "page2_normal";
		}
		if(document.getElementById("page3")){
			document.getElementById("page3").className = "page3_normal";
		}
		if(document.getElementById("page4")){
			document.getElementById("page4").className = "page4_normal";
		}
		if(document.getElementById("page5")){
			document.getElementById("page5").className = "page5_normal";
		}
		if(document.getElementById("page6")){
			document.getElementById("page6").className = "page6_checked";
		}
	}else if(flag == 7 || flag == "7"){
		changePage(5);
		nextPage();
	}else if(flag == 0 || flag == "0"){
		if(document.getElementById("page2")){
			changePage(2);
		}else{
			return;
		}	
		frontPage();
		
	}else{
		return;
	}
	return pageID;
	
}

function addPages(contentCounts, pageCounts){
	var node = document.getElementById("Pages");
	while(node.firstChild){
		node.removeChild(node.firstChild);
	}
	
	var num;
	var pageCountArray = new Array();
	
	for( num = 1; num <= contentCounts; num++ ){
		pageCountArray.push(num);	
	}	
	if(pageCounts>=6){
		node.innerHTML += "<span class='page6_normal' id='page6' onclick='changePage(7);'><font id='pageNumber6'>" + 6 + "</font></span>";
		node.innerHTML += "<span class='page5_normal' id='page5' onclick='changePage(5);'><font id='pageNumber5'>" + 5 + "</font></span>";	
		node.innerHTML += "<span class='page4_normal' id='page4' onclick='changePage(4);'><font id='pageNumber4'>" + 4 + "</font></span>";	
		node.innerHTML += "<span class='page3_normal' id='page3' onclick='changePage(3);'><font id='pageNumber3'>" + 3 + "</font></span>";	
		node.innerHTML += "<span class='page2_normal' id='page2' onclick='changePage(2);'><font id='pageNumber2'>" + 2 + "</font></span>";	
		node.innerHTML += "<span class='page1_normal' id='page1' onclick='changePage(0);'><font id='pageNumber1'>" + 1 + "</font></span>";		
	}else if(pageCounts==5){
		node.innerHTML += "<span class='page5_normal' id='page5' onclick='changePage(5);'><font id='pageNumber5'>" + 5 + "</font></span>";	
		node.innerHTML += "<span class='page4_normal' id='page4' onclick='changePage(4);'><font id='pageNumber4'>" + 4 + "</font></span>";	
		node.innerHTML += "<span class='page3_normal' id='page3' onclick='changePage(3);'><font id='pageNumber3'>" + 3 + "</font></span>";	
		node.innerHTML += "<span class='page2_normal' id='page2' onclick='changePage(2);'><font id='pageNumber2'>" + 2 + "</font></span>";	
		node.innerHTML += "<span class='page1_normal' id='page1' onclick='changePage(0);'><font id='pageNumber1'>" + 1 + "</font></span>";	
	}else if(pageCounts==4){
		node.innerHTML += "<span class='page4_normal' id='page4' onclick='changePage(4);'><font id='pageNumber4'>" + 4 + "</font></span>";	
		node.innerHTML += "<span class='page3_normal' id='page3' onclick='changePage(3);'><font id='pageNumber3'>" + 3 + "</font></span>";	
		node.innerHTML += "<span class='page2_normal' id='page2' onclick='changePage(2);'><font id='pageNumber2'>" + 2 + "</font></span>";	
		node.innerHTML += "<span class='page1_normal' id='page1' onclick='changePage(0);'><font id='pageNumber1'>" + 1 + "</font></span>";
	}else if(pageCounts==3){	
		node.innerHTML += "<span class='page3_normal' id='page3' onclick='changePage(3);'><font id='pageNumber3'>" + 3 + "</font></span>";	
		node.innerHTML += "<span class='page2_normal' id='page2' onclick='changePage(2);'><font id='pageNumber2'>" + 2 + "</font></span>";	
		node.innerHTML += "<span class='page1_normal' id='page1' onclick='changePage(0);'><font id='pageNumber1'>" + 1 + "</font></span>";
	}else if(pageCounts==2){
		//node.innerHTML += "<span class='page3_normal' id='page3' onclick='changePage(3);'><font id='pageNumber3'>" + 3 + "</font></span>";	
		node.innerHTML += "<span class='page2_normal' id='page2' onclick='changePage(2);'><font id='pageNumber2'>" + 2 + "</font></span>";	
		node.innerHTML += "<span class='page1_normal' id='page1' onclick='changePage(0);'><font id='pageNumber1'>" + 1 + "</font></span>";
	}else if(pageCounts==1){
		node.innerHTML += "<span class='page1_normal' id='page1' onclick='changePage(0);'><font id='pageNumber1'>" + 1 + "</font></span>";
	}else{
	 //alert("empty");
	}
}

function lengthToPage(length){
	var page;
	if(length == 0){
		page = 0;
	}else{
		if(parseInt(length%4) == 0){
			page = parseInt(length/4);
		}else{
			page = parseInt(length/4) + 1;
		}
	}
	return page;
}

function frontPage(){
	var i = 0;
	if(showContent.length == 0){
		return;
	}
	if(parseInt(document.getElementById("pageNumber1").firstChild.nodeValue) == currentPage){
		if(currentPage == 1){
			return;
		}else{
			alert("!");
		}
	}else if(parseInt(document.getElementById("pageNumber2").firstChild.nodeValue) == currentPage){
		changePage(1);
		if(currentPage == 1){
			return;
		
		}else{
			moveRightPageNumber();
		}
	}else if(parseInt(document.getElementById("pageNumber3").firstChild.nodeValue) == currentPage){
		changePage(2);
	}else if(parseInt(document.getElementById("pageNumber4").firstChild.nodeValue) == currentPage){
		changePage(3);
	}else if(parseInt(document.getElementById("pageNumber5").firstChild.nodeValue) == currentPage){
		changePage(4);
	}else if(parseInt(document.getElementById("pageNumber6").firstChild.nodeValue) == currentPage){
		changePage(5);
	}
}


function nextPage(){
	var lastPage;
	lastPage = lengthToPage(showContent.length);
	
	if(document.getElementById("pageNumber6") && parseInt(document.getElementById("pageNumber6").firstChild.nodeValue) == currentPage){
		if(currentPage == lastPage){			
			return;
		}else{
			alert("!");
		}
	}else if(document.getElementById("pageNumber5") && parseInt(document.getElementById("pageNumber5").firstChild.nodeValue) == currentPage){
		if(currentPage == lastPage){
			return;	
		}
		changePage(6);
		if(currentPage == lastPage){
			return;	
		}else{
			moveLeftPageNumber();
		}
	}else if(document.getElementById("pageNumber4") && parseInt(document.getElementById("pageNumber4").firstChild.nodeValue) == currentPage){
		if(currentPage == lastPage){
			return;	
		}
		changePage(5);
	}else if(document.getElementById("pageNumber3") && parseInt(document.getElementById("pageNumber3").firstChild.nodeValue) == currentPage){
		if(currentPage == lastPage){
			return;	
		}
		changePage(4);
	}else if(document.getElementById("pageNumber2") && parseInt(document.getElementById("pageNumber2").firstChild.nodeValue) == currentPage){
		if(currentPage == lastPage){
			return;	
		}
		changePage(3);
	}else if(document.getElementById("pageNumber1") && parseInt(document.getElementById("pageNumber1").firstChild.nodeValue) == currentPage){
		if(currentPage == lastPage){
			return;	
		}
		changePage(2);
	}
}


function moveLeftPageNumber(){
	
	var node = document.getElementById("Pages");
	while(node.firstChild){
		node.removeChild(node.firstChild);
	}
	var num6 = currentPage+1;
	var num5 = currentPage;
	var num4 = currentPage-1;
	var num3 = currentPage-2;
	var num2 = currentPage-3;
	var num1 = currentPage-4;
	node.innerHTML += "<span class='page6_normal' id='page6' onclick='changePage(7);'><font id='pageNumber6'>" + num6 + "</font></span>";
	node.innerHTML += "<span class='page5_normal' id='page5' onclick='changePage(5);'><font id='pageNumber5'>" + num5 + "</font></span>";	
	node.innerHTML += "<span class='page4_normal' id='page4' onclick='changePage(4);'><font id='pageNumber4'>" + num4 + "</font></span>";	
	node.innerHTML += "<span class='page3_normal' id='page3' onclick='changePage(3);'><font id='pageNumber3'>" + num3 + "</font></span>";	
	node.innerHTML += "<span class='page2_normal' id='page2' onclick='changePage(2);'><font id='pageNumber2'>" + num2 + "</font></span>";	
	node.innerHTML += "<span class='page1_normal' id='page1' onclick='changePage(0);'><font id='pageNumber1'>" + num1 + "</font></span>";		
		//alert("currenPage "+ currentPage);
	changePage(5);
}

function moveRightPageNumber(){
	var node = document.getElementById("Pages");
	while(node.firstChild){
		node.removeChild(node.firstChild);
	}
	
	var num6 = currentPage+4;
	var num5 = currentPage+3;
	var num4 = currentPage+2;
	var num3 = currentPage+1;
	var num2 = currentPage;
	var num1 = currentPage-1;
	
	node.innerHTML += "<span class='page6_normal' id='page6' onclick='changePage(7);'><font id='pageNumber6'>" + num6 + "</font></span>";
	node.innerHTML += "<span class='page5_normal' id='page5' onclick='changePage(5);'><font id='pageNumber5'>" + num5 + "</font></span>";	
	node.innerHTML += "<span class='page4_normal' id='page4' onclick='changePage(4);'><font id='pageNumber4'>" + num4 + "</font></span>";	
	node.innerHTML += "<span class='page3_normal' id='page3' onclick='changePage(3);'><font id='pageNumber3'>" + num3 + "</font></span>";	
	node.innerHTML += "<span class='page2_normal' id='page2' onclick='changePage(2);'><font id='pageNumber2'>" + num2 + "</font></span>";	
	node.innerHTML += "<span class='page1_normal' id='page1' onclick='changePage(0);'><font id='pageNumber1'>" + num1 + "</font></span>";	
	changePage(2);
}

function lastPage(){
	var lastPage;
	lastPage = lengthToPage(showContent.length);
	var i = 0;
	for(i = 0; i < lastPage; i++){
		nextPage();
	}
	
}

function firstPage(){
	var lastPage;
	lastPage = lengthToPage(showContent.length);
	for(i = 0; i < lastPage; i++){
		frontPage();
	}
}

function goButtonClicked(){
	if(!document.getElementById("pageSelect").value || document.getElementById("pageSelect").value == 0){
		alert("请输入正确的页数");
	}else{
		var i;
		var gap = parseInt(document.getElementById("pageSelect").value)-currentPage;
		if(parseInt(document.getElementById("pageSelect").value) > currentPage){
			for(i = 0; i < gap; i++){
				nextPage();
			}
		}else{
			for(i = 0; i < -gap; i++){
				frontPage();
			}
		}
	}
}

function addReReplay(){
	if (isFinished) {
		alert("任务已完成!不能继续回复！");
		return;
	}
	var arguments = "<content>";
	arguments = addTag(arguments, "username", getUserName());
	arguments = addTag(arguments, "taskId", document.getElementById("post_id").innerText);
	arguments = addTag(arguments, "body", document.getElementById("replay").value);
	arguments += "</content>";
	var url = "CreateOffer";
	sendXMLPost(url, arguments, handler);
	
}

function handler() {window.location.reload();}


function logOut() {
	window.location.href = "index.html";
}